<?php
	$member = $_POST['member'];
	$error = 0;
	
	if (empty($member)) {
		echo '<p><strong>You must select at least one group member to assign the chore to.</strong></p>';
		include("flatshare_php/bill_choreform2.php");
	}
	else {
		// code to create chore details
		$billid = createBill($_POST['billName'], $_POST['billType'], '0', $_POST['dueDate']);
		
		// code to add chore for each member passed in through the form
		if ($billid > 0) {
			foreach ($member as $username) {
				if (!addChore($billid, $username)) {
					$error = 1;
				}
			}
			if ($error == 1) {
				echo '<p>There was an error processing the chore details. Please contact an administrator.</p>';
			}
			else {
				echo '<p>The chore details have been successfully added to the database!</p>';
			}
		}
		else {
			echo '<p>There was an error processing the chore creation event. Please contact the administrator.</p>';
		}
	}
	

?>